<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
	<div class="text-left">
		<h5 class="font-blue">
			<strong>历史版本</strong>
		</h5>
		<div id="panel">
			<table class="table table-bordered" id="table">
				<thead>
					<tr class="bd_txt2">
						<th>当前版本</th>
						<th>当前状态</th>
						<th>版本简介</th>
						<th>所属平台</th>
						<th align="left">操作</th>
					</tr>
				</thead>
				{{#list}}
				<tr>
					<td><a href="javascript:versionView('{{platform}}', '{{id}}')">{{version}}</a></td>
					<td class="status">{{status}}</td>
					<td>{{release_note}}</td>
					<td>{{platformid}}</td>
					<td><button type="button" class="btn btn-primary tls btn-sm"
							name="{{status}}"
							onclick="publishApp('{{platform}}','{{id}}','{{status}}')">上架</button>
						<button class="btn btn-primary tls btn-sm"
							onclick="openCloneView('{{id}}')">克隆</button></td>
				</tr>
				{{/list}}
			</table>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
	$(function() {
		$("#table").find(".status").each(function(index) {
			var status = $(this).text();
			if (status == "5") { //下架状态
				$(this).text("已下架")
			} else if (status == "4") {//上架状态
				$(this).text("已上架")
			} else if (status == "3") {//已打包
				$(this).text("已激活")
			} else if (status == "2") {
				$(this).text("打包中")
			} else if (status == "0") {
				$(this).text("打包失败")
			} else {
				$(this).text("新建")
			}
		});

		//页面加载完，执行此函数进行判断是否显示上下架按钮
		$("button[type='button']").each(function(index) {
			var status = $(this).attr("name");
			if (status === "4") {
				$(this).attr("disabled", "disabled");
			}
		});
	})

	//进入版本详情页面
	function versionView(platform, id) {
		window.location.href = "{{ctx}}/mam/appversions/" + platform + "/" + id;
	}

	//克隆版本
	function openCloneView(cloneId) {

		var op = {
			remote : '{{ctx}}/mam/appversions/{{platform}}/clone/' + cloneId
					+ '?appId={{appId}}',
			show : true
		};
		$('#btn_modal').unbind();
		$('#btn_modal').bind("click", function() {
			dataCloneForm();
		});
		$('#myModal').modal(op);
	}

	function publishApp(platform, id, status) {
		//获取激活状态
		if (status === "0" || status === "1" || status === "2") {
			bootbox.alert("该版本还没有激活，请到版本详情页面进行激活!");
			return;
		}
		bootbox.confirm("您确定要替换架上版本吗?", function(result) {
			if (result) {
				var url = "{{ctx}}/mam/appversions/online/" + platform + "/"
						+ id;
				$.ajax({
					async : true,
					type : "PUT",
					url : url,
					dataType : 'json',
					success : function(data, textStatus) {
						if (data.result === "success") {
							bootbox.alert("上架成功！", function() {
								//window.location.href = "{{ctx}}/mam/appMain/app-view/{{appvo.id}}";
								window.location.reload();
							});
						} else {
							bootbox.alert("上架失败，请稍后再试！");
						}
					},
					error : function(data, status, e) {
						bootbox.alert("系统繁忙，请稍后再试！");
					}
				});
			}
		});
	}
</script>
